home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nebula 1
/
Nebula One.iso
/
Mail
/
pine3.92
/
pine
/
osdep
/
dialog.win
< prev
next >
Wrap
Text File
|
1996-03-13
|
9KB
|
388 lines
#line 2 "osdep/dialog.win"
/*----------------------------------------------------------------------------
Implement custom dialogs.
*/
/*
* W16 and W32 call use different names for there user data slot.
*/
#ifdef WIN32
#define WINDOW_USER_DATA GWL_USERDATA
#else
#define WINDOW_USER_DATA DWL_USER
#endif
/*===========================================================================
*
* Dialog Data
*
* The following structures hold the state data for dialogs.
*/
typedef struct DLG_TYPEMAP {
int pineid;
int rsrcid;
} DLG_TYPEMAP;
typedef struct DLG_SORTDATA {
DLG_SORTPARAM *sortsel; /* parameter structure. */
int sortcount; /* Number of different sorts. */
DLG_TYPEMAP types[20]; /* Map pine sort types to ctrl ids. */
} DLG_SORTDATA;
typedef struct DLG_FLAGDATA {
struct flag_table *ftbl;
int flagcount;
HINSTANCE hInstance;
HWND hTextWnd;
} DLG_FLAGDATA;
BOOL CALLBACK __export
sort_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK __export
flag_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
/*
* Get a button position in the parent's coordinate space.
*/
static void
GetBtnPos (HWND hPrnt, HWND hWnd, RECT *r)
{
GetWindowRect (hWnd, r);
ScreenToClient (hPrnt, (POINT *) r);
ScreenToClient (hPrnt, (POINT *) &r->right);
}
/*
* Select a sort type.
*/
int
os_sortdialog (DLG_SORTPARAM *sortsel)
{
DLGPROC dlgprc;
HINSTANCE hInst;
HWND hWnd;
int i;
DLG_SORTDATA dlgsort;
hInst = (HINSTANCE) mswin_gethinstance ();
hWnd = (HWND) mswin_gethwnd ();
/* Build a map of pine sort types to the resource types. */
i = 0;
dlgsort.types[i].pineid = SortArrival;
dlgsort.types[i++].rsrcid = IDC_SORTARRIVAL;
dlgsort.types[i].pineid = SortDate;
dlgsort.types[i++].rsrcid = IDC_SORTDATE;
dlgsort.types[i].pineid = SortFrom;
dlgsort.types[i++].rsrcid = IDC_SORTFROM;
dlgsort.types[i].pineid = SortSubject;
dlgsort.types[i++].rsrcid = IDC_SORTSUBJECT;
dlgsort.types[i].pineid = SortSubject2;
dlgsort.types[i++].rsrcid = IDC_SORTORDERSUB;
dlgsort.types[i].pineid = SortTo;
dlgsort.types[i++].rsrcid = IDC_SORTTO;
dlgsort.types[i].pineid = SortCc;
dlgsort.types[i++].rsrcid = IDC_SORTCC;
dlgsort.types[i].pineid = SortSize;
dlgsort.types[i++].rsrcid = IDC_SORTSIZE;
dlgsort.sortcount = i;
dlgsort.sortsel = sortsel;
#ifndef WIN32
/* WIN32 obsolete */
dlgprc = (DLGPROC) MakeProcInstance ((FARPROC) sort_dialog_proc,
hInst);
#else
dlgprc = sort_dialog_proc;
#endif
DialogBoxParam (hInst, MAKEINTRESOURCE (IDD_SELECTSORT), hWnd,
dlgprc, (LPARAM)&dlgsort);
#ifndef WIN32
/* WIN32 obsolete */
FreeProcInstance (dlgprc);
#endif
}
/*
* Dialog proc to handle index sort selection.
*
* Configures the dialog box on init and retrieves the settings on exit.
*/
BOOL CALLBACK __export
sort_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
DLG_SORTDATA *dlgsort;
BOOL ret = FALSE;
int cursort;
int i;
switch (uMsg) {
case WM_INITDIALOG:
dlgsort = (DLG_SORTDATA *)lParam;
SetWindowLong (hDlg, WINDOW_USER_DATA, (LONG) dlgsort);
/* Set the reversed button state. */
CheckDlgButton (hDlg, IDC_SORTREVERSE, dlgsort->sortsel->reverse);
/* Set the current sort type radio button.*/
cursort = IDC_SORTARRIVAL;
for (i = 0; i < dlgsort->sortcount; ++i) {
if (dlgsort->types[i].pineid == dlgsort->sortsel->cursort) {
cursort = dlgsort->types[i].rsrcid;
break;
}
}
CheckRadioButton (hDlg, IDC_SORTARRIVAL, IDC_SORTDATE, cursort);
EnableWindow (GetDlgItem (hDlg, IDC_GETHELP),
(dlgsort->sortsel->helptext != NULL));
return (1);
case WM_COMMAND:
dlgsort = (DLG_SORTDATA *) GetWindowLong (hDlg, WINDOW_USER_DATA);
switch (wParam) {
case IDC_GETHELP:
if (dlgsort->sortsel->helptext)
mswin_showhelpmsg ((WINHAND)hDlg, dlgsort->sortsel->helptext);
ret = TRUE;
break;
case IDOK:
dlgsort->sortsel->rval = 1;
/* Retrieve the reverse sort state. */
dlgsort->sortsel->reverse = (IsDlgButtonChecked (hDlg, IDC_SORTREVERSE) == 1);
/* Retrieve the new sort type. */
for (i = 0; i < dlgsort->sortcount; ++i) {
if (IsDlgButtonChecked (hDlg, dlgsort->types[i].rsrcid)) {
dlgsort->sortsel->cursort = dlgsort->types[i].pineid;
break;
}
}
EndDialog (hDlg, dlgsort->sortsel->rval);
ret = TRUE;
break;
case IDCANCEL:
dlgsort->sortsel->rval = 0;
ret = TRUE;
EndDialog (hDlg, dlgsort->sortsel->rval);
break;
}
break;
}
return (ret);
}
/*
* Select message flags.
*/
int
os_flagmsgdialog (struct flag_table *ftbl)
{
DLGPROC dlgprc;
HINSTANCE hInst;
HWND hWnd;
int i;
DLG_FLAGDATA dlgflag;
int rval;
hInst = (HINSTANCE) mswin_gethinstance ();
hWnd = (HWND) mswin_gethwnd ();
dlgflag.ftbl = ftbl;
dlgflag.hInstance = hInst;
dlgflag.hTextWnd = hWnd;
#ifndef WIN32
/* WIN32 obsolete */
dlgprc = (DLGPROC) MakeProcInstance ((FARPROC) flag_dialog_proc,
hInst);
#else
dlgprc = flag_dialog_proc;
#endif
rval = DialogBoxParam (hInst, MAKEINTRESOURCE (IDD_SELECTFLAG), hWnd,
dlgprc, (LPARAM)&dlgflag);
#ifndef WIN32
/* WIN32 obsolete */
FreeProcInstance (dlgprc);
#endif
return (rval);
}
/*
* Dialog proc to handle flag selection.
*
* Configures the dialog box on init, adding buttons as needed for
* an unknown number of flags.
* Retrieves the settings on exit.
*/
BOOL CALLBACK __export
flag_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
DLG_FLAGDATA *dlgflag;
BOOL ret = FALSE;
int i;
struct flag_table *fp;
HWND hRB[2], hBtn;
RECT rb[2];
UINT bheight, bwidth, bvertSpace;
UINT btnOKHeight;
int base, line;
int bstate;
HFONT btnFont;
switch (uMsg) {
case WM_INITDIALOG:
dlgflag = (DLG_FLAGDATA *)lParam;
SetWindowLong (hDlg, WINDOW_USER_DATA, (LONG) dlgflag);
/* Count buttons */
dlgflag->flagcount = 0;
for (fp = dlgflag->ftbl; fp && fp->name; ++fp)
++dlgflag->flagcount;
/* Get the positions of the current buttons. */
for (i = 0; i < 2; ++i) {
hRB[i] = GetDlgItem (hDlg, IDC_FLAGCOL1 + i);
GetBtnPos (hDlg, hRB[i], &rb[i]);
}
bheight = rb[0].bottom - rb[0].top;
bwidth = rb[0].right - rb[0].left;
bvertSpace = bheight + 5;
btnFont = (HFONT) SendMessage (hRB[0], WM_GETFONT, 0, 0);
for (i = 0; i < dlgflag->flagcount; ++i) {
fp = &dlgflag->ftbl[i];
if (i < 2) {
hBtn = hRB[i];
SetWindowText (hBtn, fp->name);
}
else {
base = i % 2;
line = i / 2;
hBtn = CreateWindow ("BUTTON", fp->name,
WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
rb[base].left, rb[base].top + bvertSpace * line,
bwidth, bheight,
hDlg, (HMENU)NULL, dlgflag->hInstance, NULL);
#ifdef WIN32
SetWindowLong (hBtn, GWL_ID, IDC_FLAGCOL1 + i);
#else
SetWindowWord (hBtn, GWW_ID, IDC_FLAGCOL1 + i);
#endif
SendMessage (hBtn, WM_SETFONT, (WPARAM)btnFont,
MAKELPARAM (0, 0));
}
if (fp->ukn)
SendMessage (hBtn, BM_SETSTYLE,
(WPARAM)(BS_CHECKBOX | BS_AUTO3STATE), 0);
SendMessage (hBtn, BM_SETCHECK,
(WPARAM) fp->set == CMD_FLAG_UNKN ? 2 : fp->set ? 1 : 0,
0);
ShowWindow (hBtn, SW_SHOW);
EnableWindow (hBtn, TRUE);
}
/* Position the OK and Cancel buttons. */
line = (dlgflag->flagcount + 1) / 2;
for (i = 0; i < 2; ++i) {
hRB[1] = GetDlgItem (hDlg, i == 0 ? IDOK : IDCANCEL);
GetBtnPos (hDlg, hRB[1], &rb[1]);
MoveWindow (hRB[1], rb[1].left, rb[0].top + bvertSpace * line,
rb[1].right - rb[1].left, rb[1].bottom - rb[1].top,
FALSE);
btnOKHeight = rb[1].bottom - rb[1].top;
}
/* Resize whole dialog window. */
GetWindowRect (hDlg, &rb[1]);
rb[1].right -= rb[1].left;
rb[1].bottom = rb[0].top + bvertSpace * line + btnOKHeight + 10 +
GetSystemMetrics (SM_CYCAPTION);
MoveWindow (hDlg, rb[1].left, rb[1].top, rb[1].right,
rb[1].bottom, TRUE);
return (1);
case WM_COMMAND:
dlgflag = (DLG_FLAGDATA *) GetWindowLong (hDlg, WINDOW_USER_DATA);
switch (wParam) {
case IDOK:
/* Retrieve the button states. */
for (i = 0; i < dlgflag->flagcount; ++i) {
fp = &dlgflag->ftbl[i];
bstate = SendMessage (GetDlgItem (hDlg, IDC_FLAGCOL1 + i),
BM_GETCHECK, 0, 0);
switch (bstate) {
case 2: fp->set = CMD_FLAG_UNKN; break;
case 1: fp->set = CMD_FLAG_SET; break;
case 0: fp->set = CMD_FLAG_CLEAR; break;
}
}
EndDialog (hDlg, TRUE);
ret = TRUE;
break;
case IDCANCEL:
EndDialog (hDlg, FALSE);
ret = TRUE;
break;
}
break;
}
return (ret);
}